<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="baidu-site-verification" content="WTTWi2XnJ5">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Josefin Sans:300,300italic,400,400italic,700,700italic|Lobster:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"lclong.top","root":"/","scheme":"Gemini","version":"7.7.1","exturl":true,"sidebar":{"position":"left","display":"post","padding":20,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="这篇文章是我在学校大数据课的一篇论文，有兴趣的可以详细了解。 一、研究意义在当今NBA的时代背景下，左右球队能在一个赛季走多远的不止是教练的精妙布置和球员在场上的努力发挥，球队在休赛期间的交易十分重要，比如2017年杜兰特加盟勇士队，和联盟第一球星詹姆斯的几次转回，还有猛龙与马刺的交易等，这些重磅交易不仅引起了巨大的关注，同时也为近几年来NBA总冠军的归属和联盟的格局埋下了伏笔。不止是超级巨星，包">
<meta property="og:type" content="article">
<meta property="og:title" content="基于BP神经网络的NBA球员薪资评估">
<meta property="og:url" content="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/index.html">
<meta property="og:site_name" content="Zlatanlong&#39;s T-blog">
<meta property="og:description" content="这篇文章是我在学校大数据课的一篇论文，有兴趣的可以详细了解。 一、研究意义在当今NBA的时代背景下，左右球队能在一个赛季走多远的不止是教练的精妙布置和球员在场上的努力发挥，球队在休赛期间的交易十分重要，比如2017年杜兰特加盟勇士队，和联盟第一球星詹姆斯的几次转回，还有猛龙与马刺的交易等，这些重磅交易不仅引起了巨大的关注，同时也为近几年来NBA总冠军的归属和联盟的格局埋下了伏笔。不止是超级巨星，包">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/image-20200217163219161.png">
<meta property="og:image" content="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/image-20200217163239394.png">
<meta property="og:image" content="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/%E5%9B%BE%E7%89%871.png">
<meta property="og:image" content="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/%E5%9B%BE%E7%89%872-1.png">
<meta property="og:image" content="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/%E5%9B%BE%E7%89%872-2.png">
<meta property="og:image" content="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/%E5%9B%BE%E7%89%872-3.png">
<meta property="article:published_time" content="2019-07-01T08:21:35.000Z">
<meta property="article:modified_time" content="2019-07-01T08:21:35.000Z">
<meta property="article:author" content="Zlatanlong">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="BP">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/image-20200217163219161.png">

<link rel="canonical" href="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>基于BP神经网络的NBA球员薪资评估 | Zlatanlong's T-blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Zlatanlong's T-blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">Lakers is Championship!</h1>
      
  </div>

  <div class="site-nav-right"></div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">31</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">38</span></a>

  </li>
        <li class="menu-item menu-item-aboutme">

    <a href="/aboutme/" rel="section"><i class="fa fa-fw fa-user"></i>博主</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Zlatanlong">
      <meta itemprop="description" content="生活就像巧克力🍫">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Zlatanlong's T-blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          基于BP神经网络的NBA球员薪资评估
        </h2>

        <div class="post-meta">
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-07-01 16:21:35" itemprop="dateCreated datePublished" datetime="2019-07-01T16:21:35+08:00">2019-07-01</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/" itemprop="url" rel="index">
                    <span itemprop="name">大数据</span>
                  </a>
                </span>
            </span>

          
            <span id="/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/" class="post-meta-item leancloud_visitors" data-flag-title="基于BP神经网络的NBA球员薪资评估" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">评论次数：</span>
    
    <a title="valine" href="/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>9.1k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>23 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>这篇文章是我在学校大数据课的一篇论文，有兴趣的可以详细了解。</p>
<h1 id="一、研究意义"><a href="#一、研究意义" class="headerlink" title="一、研究意义"></a>一、研究意义</h1><p>在当今NBA的时代背景下，左右球队能在一个赛季走多远的不止是教练的精妙布置和球员在场上的努力发挥，球队在休赛期间的交易十分重要，比如2017年杜兰特加盟勇士队，和联盟第一球星詹姆斯的几次转回，还有猛龙与马刺的交易等，这些重磅交易不仅引起了巨大的关注，同时也为近几年来NBA总冠军的归属和联盟的格局埋下了伏笔。不止是超级巨星，包括明星球员和重要角色球员的转回，都可能为球队的比赛以及运营带来巨大的影响；而交易最重要得一个环节就是薪水的评估，球队和球员双方可能需要很多人员对球员的场上数据，身体条件进行评估，同时基于市场考虑谈判出一个令双方都满意的结果。因此我针对这一现象，基于老师提供的BP神经网络算法和相关实现代码，提出一套评估球员薪水的解决方案，这套方案还有很大不足和需要进步之处，希望能够在日后的学习中不断弥补。</p>
<a id="more"></a>

<h1 id="二、数据描述"><a href="#二、数据描述" class="headerlink" title="二、数据描述"></a>二、数据描述</h1><p>国内的虎扑社区提供了NBA的篮球数据，供球迷使用，其中包括了球员的合同和当季薪资，这里我使用requests库来发送http请求，使用BeautifulSoup库解析html。数据来源网站即是<span class="exturl" data-url="aHR0cHM6Ly9uYmEuaHVwdS5jb20vcGxheWVycw==" title="https://nba.hupu.com/players">虎扑网站<i class="fa fa-external-link"></i></span>。</p>
<p><strong>表2-1 数据属性结构</strong></p>
<table>
<thead>
<tr>
<th><strong>属性</strong></th>
<th><strong>作用</strong></th>
<th><strong>属性</strong></th>
<th><strong>作用</strong></th>
</tr>
</thead>
<tbody><tr>
<td>场均得分</td>
<td>神经元输入</td>
<td>场均三分命中率</td>
<td>神经元输入</td>
</tr>
<tr>
<td>场均篮板</td>
<td>神经元输入</td>
<td>场均罚球命中率</td>
<td>神经元输入</td>
</tr>
<tr>
<td>场均助攻</td>
<td>神经元输入</td>
<td>场均抢断</td>
<td>神经元输入</td>
</tr>
<tr>
<td>场均投篮命中率</td>
<td>神经元输入</td>
<td>场均盖帽</td>
<td>神经元输入</td>
</tr>
<tr>
<td>薪资水平</td>
<td>神经元输出</td>
<td></td>
<td></td>
</tr>
</tbody></table>
<p>我爬取了2018-2019赛季常规赛30个球队每名球员的场均得分，场均篮板，场均助攻，场均抢断，场均盖帽，场均投篮命中率，场均三分命中率，场均罚球命中率，当季共9个属性，497条数据。在预处理过程中将当季薪资为0或者没有信息的数据删除，因为这些球员可能别没有签约，其他8项属性作为输入神经元，并将球员按照薪资水平，每500W美元为一个档次，构建出可以与输出矩阵做算术运算格式匹配的响应的Y矩阵。</p>
<p>如表2-1所示，通过numpy库的save方法将数据保存，如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">save(<span class="string">"date_players.npy"</span>, date_players)</span><br></pre></td></tr></table></figure>

<h2 id="预处理："><a href="#预处理：" class="headerlink" title="预处理："></a>预处理：</h2><p>如果在爬取数据过程中球员薪水没有获取到，说明该球员可能没有签约，因此将该数据删除，代码如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 预处理</span></span><br><span class="line"></span><br><span class="line">    data = pd.DataFrame(date_players)</span><br><span class="line"></span><br><span class="line">    data_salary = data.iloc[:,<span class="number">8</span>]</span><br><span class="line"></span><br><span class="line">    data_salary[data_salary == <span class="number">0</span>] = np.NAN</span><br><span class="line"></span><br><span class="line">    data_new = np.hstack((date_players[:,:<span class="number">8</span>], np.array([data_salary]).T))</span><br><span class="line"></span><br><span class="line">    data2 = pd.DataFrame(data_new).dropna(thresh=<span class="number">9</span>)</span><br><span class="line"></span><br><span class="line">    date_players_new = np.array(data2)</span><br><span class="line"></span><br><span class="line">    xdata_ori = date_players_new[:,:<span class="number">8</span>]</span><br><span class="line"></span><br><span class="line">    salary_ori = date_players_new[:,<span class="number">8</span>]//<span class="number">500</span> <span class="comment">#以500W为间隔</span></span><br><span class="line">    </span><br><span class="line"><span class="comment"># 预处理结束</span></span><br></pre></td></tr></table></figure>

<h2 id="归一化："><a href="#归一化：" class="headerlink" title="归一化："></a>归一化：</h2><p>在我分析完老师提供的bp神经网络代码实现后，发现其中使用的S函数等函数，值域在[0,1]之间，因此神经元的输入必须进行归一化处理，否则将可能报错；同时归一化处理也将神经元输入的各种数据进行平权处理。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 归一化</span></span><br><span class="line"></span><br><span class="line">    maxVals = xdata_ori.max(<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line">    minVals = xdata_ori.min(<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line">    ranges = maxVals - minVals</span><br><span class="line"></span><br><span class="line">    m = xdata_ori.shape[<span class="number">0</span>]</span><br><span class="line"></span><br><span class="line">    normDataSet = (xdata_ori - np.tile(minVals, (m, <span class="number">1</span>))) / np.tile(ranges, (m, <span class="number">1</span>))</span><br><span class="line"></span><br><span class="line">    trainX = normDataSet.T</span><br><span class="line"><span class="comment"># 归一化结束</span></span><br></pre></td></tr></table></figure>

<h2 id="处理Y矩阵："><a href="#处理Y矩阵：" class="headerlink" title="处理Y矩阵："></a>处理Y矩阵：</h2><p>因为爬取到的只是薪资数据，为了跑通BP神经网络算法，必须将数据进行处理，处理方法为：根据输出长度生成一列0矩阵，根据薪资水平的档次将该矩阵的某一个数据设置为1，在bp神经网络进行迭代的过程中，每一次向前传递都会得出一组输出<code>tempY</code>，其中<code>tempY</code>中每个数据及为是这一类的概率有多少，使用处理过的Y矩阵与<code>tempY</code>进行数学运算即可向后传递，不断迭代即可训练出合适的参数。</p>
<h1 id="三、模型描述"><a href="#三、模型描述" class="headerlink" title="三、模型描述"></a>三、模型描述</h1><h2 id="典型的神经元模型："><a href="#典型的神经元模型：" class="headerlink" title="典型的神经元模型："></a>典型的神经元模型：</h2><p><img src="/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/image-20200217163219161.png" alt="典型的神经元模型"></p>
<h2 id="神经网络结构（单一输出）："><a href="#神经网络结构（单一输出）：" class="headerlink" title="神经网络结构（单一输出）："></a>神经网络结构（单一输出）：</h2><p><img src="/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/image-20200217163239394.png" alt="神经网络结构"></p>
<h2 id="BP神经网络基本原理："><a href="#BP神经网络基本原理：" class="headerlink" title="BP神经网络基本原理："></a>BP神经网络基本原理：</h2><p>分为两个过程：</p>
<p>工作信号正向传递子过程，输入信息从输入层经隐层逐层、正向传递，直至得到各计算单元的输出。</p>
<p>误差信号反向传递子过程，输出层误差从输出层开始，逐层、反向传播，可间接计算隐层各单元的误差，并用此误差修正前层的权值。</p>
<p>Bp算法主要函数如下：</p>
<ul>
<li><p><code>iniPara()</code>：根据给定的神经网络结构根据正态分布随机初始化一套参数；</p>
</li>
<li><p><code>forwardModel(X, parameters)</code>：一个完整的向前传播过程，根据输入X和神经网络中间参数parameters，返回输出和中间每一层的参数。</p>
</li>
<li><p><code>backwardModel(AL, Y, caches)</code>：完整的反向传播过程，根据输出和真实的Y矩阵进行计算，同时计算每一隐含层梯度，返回梯度矩阵diffs</p>
</li>
<li><p><code>updateParameters(parameters, diffs, learningRate)</code>：根据之前的参数，梯度矩阵diffs和学习率，进行参数更新，返回新的参数。</p>
</li>
<li><p><code>predict(X, y, parameters, ifPrint)</code>：预测函数，根据训练好的参数和新的输入，预测输出，并且可以和实际情况Y做对比，根据ifPrint是否打印输出算法准确率。</p>
</li>
</ul>
<h1 id="四、算法实现"><a href="#四、算法实现" class="headerlink" title="四、算法实现:"></a>四、算法实现:</h1><p>经过精读老师提供的bp神经网络实现代码，发现其中核心函数中可以修改地方只有激活函数的选取可以更改，而根据bp神经网络原理可知，在神经网络的中间层更加建议使用<code>relu函数</code>。</p>
<p>如果<code>bp神经网络</code>的输出不是单输出，<code>predict函数</code>需要进行修改(位于代码最后)，我对该函数进行修改后使其能够应对多种输出情况，代码如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python3</span></span><br><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="string">"""</span></span><br><span class="line"><span class="string">Created on Sat Oct 14 09:54:44 2017</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">@author: zhangshichaochina@gmail.com</span></span><br><span class="line"><span class="string">"""</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> h5py</span><br><span class="line"><span class="keyword">import</span> scipy</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image</span><br><span class="line"><span class="keyword">from</span> scipy <span class="keyword">import</span> ndimage</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">sigmoid</span><span class="params">(z)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    使用numpy实现sigmoid函数</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    Z numpy array</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    A 激活值（维数和Z完全相同）</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">1</span>/(<span class="number">1</span> + np.exp(-z))</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">relu</span><span class="params">(z)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    线性修正函数relu</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    z numpy array</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    A 激活值（维数和Z完全相同）</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    <span class="keyword">return</span> np.array(z&gt;<span class="number">0</span>)*z</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">sigmoidBackward</span><span class="params">(dA, cacheA)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    sigmoid的反向传播</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    dA 同层激活值</span></span><br><span class="line"><span class="string">    cacheA 同层线性输出</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    dZ 梯度</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    s = sigmoid(cacheA)</span><br><span class="line">    diff = s*(<span class="number">1</span> - s)</span><br><span class="line">    dZ = dA * diff</span><br><span class="line">    <span class="keyword">return</span> dZ</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">reluBackward</span><span class="params">(dA, cacheA)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    relu的反向传播</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    dA 同层激活值</span></span><br><span class="line"><span class="string">    cacheA 同层线性输出</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    dZ 梯度</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    Z = cacheA</span><br><span class="line">    dZ = np.array(dA, copy=<span class="literal">True</span>) </span><br><span class="line">    dZ[Z &lt;= <span class="number">0</span>] = <span class="number">0</span></span><br><span class="line">    <span class="keyword">return</span> dZ</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">iniPara</span><span class="params">(laydims)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    随机初始化网络参数</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    laydims 一个python list</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    parameters 随机初始化的参数字典（”W1“，”b1“，”W2“，”b2“, ...）</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    np.random.seed(<span class="number">1</span>)</span><br><span class="line">    parameters = &#123;&#125;</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1</span>, len(laydims)):</span><br><span class="line">        parameters[<span class="string">'W'</span>+str(i)] = np.random.randn(laydims[i], laydims[i<span class="number">-1</span>])/ np.sqrt(laydims[i<span class="number">-1</span>])</span><br><span class="line">        parameters[<span class="string">'b'</span>+str(i)] = np.zeros((laydims[i], <span class="number">1</span>))</span><br><span class="line">    <span class="keyword">return</span> parameters</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">loadData</span><span class="params">(dataDir)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    导入数据</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    dataDir 数据集路径</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    训练集，测试集以及标签</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    train_dataset = h5py.File(dataDir+<span class="string">'/train.h5'</span>, <span class="string">"r"</span>)</span><br><span class="line">    train_set_x_orig = np.array(train_dataset[<span class="string">"train_set_x"</span>][:]) <span class="comment"># your train set features</span></span><br><span class="line">    train_set_y_orig = np.array(train_dataset[<span class="string">"train_set_y"</span>][:]) <span class="comment"># your train set labels</span></span><br><span class="line"></span><br><span class="line">    test_dataset = h5py.File(dataDir+<span class="string">'/test.h5'</span>, <span class="string">"r"</span>)</span><br><span class="line">    test_set_x_orig = np.array(test_dataset[<span class="string">"test_set_x"</span>][:]) <span class="comment"># your test set features</span></span><br><span class="line">    test_set_y_orig = np.array(test_dataset[<span class="string">"test_set_y"</span>][:]) <span class="comment"># your test set labels</span></span><br><span class="line"></span><br><span class="line">    classes = np.array(test_dataset[<span class="string">"list_classes"</span>][:]) <span class="comment"># the list of classes</span></span><br><span class="line">    </span><br><span class="line">    train_set_y_orig = train_set_y_orig.reshape((<span class="number">1</span>, train_set_y_orig.shape[<span class="number">0</span>]))</span><br><span class="line">    test_set_y_orig = test_set_y_orig.reshape((<span class="number">1</span>, test_set_y_orig.shape[<span class="number">0</span>]))</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">forwardLinear</span><span class="params">(W, b, A_prev)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    前向传播</span></span><br><span class="line"><span class="string">    特征乘权值+b</span></span><br><span class="line"><span class="string">    Z 就是乘激活函数前的东西</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    Z = np.dot(W, A_prev) + b</span><br><span class="line">    cache = (W, A_prev, b)</span><br><span class="line">    <span class="keyword">return</span> Z, cache</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">forwardLinearActivation</span><span class="params">(W, b, A_prev, activation)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    带激活函数的前向传播</span></span><br><span class="line"><span class="string">    A: 加上激活函数的效果</span></span><br><span class="line"><span class="string">    cacheL: 最原始的参数</span></span><br><span class="line"><span class="string">    cacheA: 加权后的参数</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    Z, cacheL = forwardLinear(W, b, A_prev)</span><br><span class="line">    cacheA = Z</span><br><span class="line">    <span class="keyword">if</span> activation == <span class="string">'sigmoid'</span>:</span><br><span class="line">        A = sigmoid(Z)</span><br><span class="line">    <span class="keyword">if</span> activation == <span class="string">'relu'</span>:</span><br><span class="line">        A = relu(Z)</span><br><span class="line">    cache = (cacheL, cacheA)</span><br><span class="line">    <span class="keyword">return</span> A, cache</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">forwardModel</span><span class="params">(X, parameters)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    完整的前向传播过程</span></span><br><span class="line"><span class="string">    X: 训练集特征</span></span><br><span class="line"><span class="string">    AL: 完整前项传播得到的输出</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    layerdim = len(parameters)//<span class="number">2</span> <span class="comment">#有几层对应隐含层</span></span><br><span class="line">    caches = []</span><br><span class="line">    A_prev = X</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1</span>, layerdim):</span><br><span class="line">        A_prev, cache = forwardLinearActivation(parameters[<span class="string">'W'</span>+str(i)], parameters[<span class="string">'b'</span>+str(i)], A_prev, <span class="string">'relu'</span>)</span><br><span class="line">        caches.append(cache)</span><br><span class="line">        </span><br><span class="line">    AL, cache = forwardLinearActivation(parameters[<span class="string">'W'</span>+str(layerdim)], parameters[<span class="string">'b'</span>+str(layerdim)], A_prev, <span class="string">'sigmoid'</span>)</span><br><span class="line">    caches.append(cache)</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> AL, caches</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">computeCost</span><span class="params">(AL, Y)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    代价函数的计算</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    AL 输出层的激活输出</span></span><br><span class="line"><span class="string">    Y 标签值</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    cost 代价函数值</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    m = Y.shape[<span class="number">1</span>]</span><br><span class="line">    cost = (<span class="number">1.</span>/m) * (-np.dot(Y,np.log(AL).T) - np.dot(<span class="number">1</span>-Y, np.log(<span class="number">1</span>-AL).T))</span><br><span class="line">    <span class="keyword">return</span> cost</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">linearBackward</span><span class="params">(dZ, cache)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    线性部分的反向传播</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    dZ 当前层误差</span></span><br><span class="line"><span class="string">    cache （W, A_prev, b）元组</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    dA_prev 上一层激活的梯度</span></span><br><span class="line"><span class="string">    dW 当前层W的梯度</span></span><br><span class="line"><span class="string">    db 当前层b的梯度</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    W, A_prev, b = cache</span><br><span class="line">    m = A_prev.shape[<span class="number">1</span>]</span><br><span class="line">    </span><br><span class="line">    dW = <span class="number">1</span>/m*np.dot(dZ, A_prev.T)</span><br><span class="line">    db = <span class="number">1</span>/m*np.sum(dZ, axis = <span class="number">1</span>, keepdims=<span class="literal">True</span>)</span><br><span class="line">    dA_prev = np.dot(W.T, dZ)</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> dA_prev, dW, db</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">linearActivationBackward</span><span class="params">(dA, cache, activation)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    非线性部分的反向传播</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    dA 当前层激活输出的梯度</span></span><br><span class="line"><span class="string">    cache （W, A_prev, b）元组</span></span><br><span class="line"><span class="string">    activation 激活函数类型</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    dA_prev 上一层激活的梯度</span></span><br><span class="line"><span class="string">    dW 当前层W的梯度</span></span><br><span class="line"><span class="string">    db 当前层b的梯度</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    cacheL, cacheA = cache</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">if</span> activation == <span class="string">'relu'</span>:</span><br><span class="line">        dZ = reluBackward(dA, cacheA)</span><br><span class="line">        dA_prev, dW, db = linearBackward(dZ, cacheL)</span><br><span class="line">    <span class="keyword">elif</span> activation == <span class="string">'sigmoid'</span>:</span><br><span class="line">        dZ = sigmoidBackward(dA, cacheA)</span><br><span class="line">        dA_prev, dW, db = linearBackward(dZ, cacheL)</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> dA_prev, dW, db</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">backwardModel</span><span class="params">(AL, Y, caches)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    完整的反向传播过程</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    AL 输出层结果</span></span><br><span class="line"><span class="string">    Y 标签值</span></span><br><span class="line"><span class="string">    caches [cacheL, cacheA]</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    diffs 梯度字典</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    layerdim = len(caches)</span><br><span class="line">    Y = Y.reshape(AL.shape)</span><br><span class="line">    L = layerdim</span><br><span class="line">    </span><br><span class="line">    diffs = &#123;&#125;</span><br><span class="line">    </span><br><span class="line">    dAL = - (np.divide(Y, AL) - np.divide(<span class="number">1</span> - Y, <span class="number">1</span> - AL))</span><br><span class="line">    </span><br><span class="line">    currentCache = caches[L<span class="number">-1</span>]</span><br><span class="line">    dA_prev, dW, db =  linearActivationBackward(dAL, currentCache, <span class="string">'sigmoid'</span>)</span><br><span class="line">    diffs[<span class="string">'dA'</span> + str(L)], diffs[<span class="string">'dW'</span>+str(L)], diffs[<span class="string">'db'</span>+str(L)] = dA_prev, dW, db</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">for</span> l <span class="keyword">in</span> reversed(range(L<span class="number">-1</span>)):</span><br><span class="line">        currentCache = caches[l]</span><br><span class="line">        dA_prev, dW, db =  linearActivationBackward(dA_prev, currentCache, <span class="string">'relu'</span>)</span><br><span class="line">        diffs[<span class="string">'dA'</span> + str(l+<span class="number">1</span>)], diffs[<span class="string">'dW'</span>+str(l+<span class="number">1</span>)], diffs[<span class="string">'db'</span>+str(l+<span class="number">1</span>)] = dA_prev, dW, db</span><br><span class="line">        </span><br><span class="line">    <span class="keyword">return</span> diffs</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">updateParameters</span><span class="params">(parameters, diffs, learningRate)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    更新参数</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    parameters 待更新网络参数</span></span><br><span class="line"><span class="string">    diffs 梯度字典</span></span><br><span class="line"><span class="string">    learningRate 学习率</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    parameters 网络参数字典</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    layerdim = len(parameters)//<span class="number">2</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1</span>, layerdim+<span class="number">1</span>):</span><br><span class="line">        parameters[<span class="string">'W'</span>+str(i)] -= learningRate*diffs[<span class="string">'dW'</span>+str(i)]</span><br><span class="line">        parameters[<span class="string">'b'</span>+str(i)] -= learningRate*diffs[<span class="string">'db'</span>+str(i)]</span><br><span class="line">    <span class="keyword">return</span> parameters</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">finalModel</span><span class="params">(X, Y, layerdims, learningRate=<span class="number">0.01</span>, numIters=<span class="number">5000</span>,pringCost=False)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    最终的BP神经网络模型</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    X 训练集特征</span></span><br><span class="line"><span class="string">    Y 训练集标签</span></span><br><span class="line"><span class="string">    layerdims 一个明确网络结构的python list</span></span><br><span class="line"><span class="string">    learningRate 学习率</span></span><br><span class="line"><span class="string">    numIters 迭代次数</span></span><br><span class="line"><span class="string">    pringCost 打印标志</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    parameters 参数字典</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    np.random.seed(<span class="number">1</span>)</span><br><span class="line">    costs = []</span><br><span class="line">    </span><br><span class="line">    parameters = iniPara(layerdims)</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">0</span>, numIters):</span><br><span class="line">        AL, caches = forwardModel(X, parameters)</span><br><span class="line">        cost = computeCost(AL, Y)</span><br><span class="line">        </span><br><span class="line">        diffs = backwardModel(AL,Y, caches)</span><br><span class="line">        parameters = updateParameters(parameters,diffs, learningRate)</span><br><span class="line">    </span><br><span class="line">        <span class="keyword">if</span> pringCost <span class="keyword">and</span> i%<span class="number">100</span> == <span class="number">0</span>:</span><br><span class="line">            print(cost)</span><br><span class="line">            costs.append(np.sum(cost))</span><br><span class="line">    <span class="keyword">return</span> parameters</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">predict</span><span class="params">(X, y, parameters, ifPrint)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    在测试集上预测</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">    X 输入特征值</span></span><br><span class="line"><span class="string">    y 测试集标签</span></span><br><span class="line"><span class="string">    parameters 参数字典</span></span><br><span class="line"><span class="string">    输出：</span></span><br><span class="line"><span class="string">    p 预测得到的标签</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    </span><br><span class="line">    m = X.shape[<span class="number">1</span>]</span><br><span class="line">    n = len(parameters) // <span class="number">2</span> </span><br><span class="line">    p = np.zeros((<span class="number">1</span>,m))</span><br><span class="line">    probas, caches = forwardModel(X, parameters)</span><br><span class="line">    truth = np.argmax(y,<span class="number">0</span>)</span><br><span class="line">    pre = np.argmax(probas,<span class="number">0</span>)</span><br><span class="line">    <span class="keyword">if</span> ifPrint:</span><br><span class="line">        print(<span class="string">"Accuracy: "</span>  + str(np.sum((pre == truth)/m)))</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> pre, np.sum((pre == truth)/m)</span><br></pre></td></tr></table></figure>

<p>其他算法实现均为原bp神经网络代码实现。</p>
<h1 id="五、运行结果及意义说明"><a href="#五、运行结果及意义说明" class="headerlink" title="五、运行结果及意义说明:"></a>五、运行结果及意义说明:</h1><p><img src="/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/%E5%9B%BE%E7%89%871.png" alt="图1 验证训练集准确率"></p>
<p>对训练集的准确率验证如图1，发现在学习率为0.8，迭代次数为20600次时，准确率最高。因此考虑用该参数。</p>
<p><img src="/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/%E5%9B%BE%E7%89%872-1.png" alt="图2-1 勒布朗·詹姆斯薪水预测"></p>
<p><img src="/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/%E5%9B%BE%E7%89%872-2.png" alt="图2-2 小乔丹薪水预测"></p>
<p><img src="/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/%E5%9B%BE%E7%89%872-3.png" alt="图2-3 路易斯·威廉姆斯薪水预测"></p>
<p>图2-1，2-2，2-3分别对三名不同类型球员进行了薪水预测，完全符合市场情况，其中小乔丹刚刚以1000万美元的年薪加盟网队，可以说是名副其实的降薪了，而快船队的路易斯·威廉姆斯实际合同只有700万美元，也是物美价廉了，勒布朗虽然上赛季受伤，但是依然可以打出自己的价值，预测薪水也和实际相符。</p>
<h1 id="六、总结"><a href="#六、总结" class="headerlink" title="六、总结"></a>六、总结</h1><p>在实现这次基于bp神经网络算法的应用过程中，自己第一次亲身体验到了神经网络算法的实现过程，在对老师的实现代码进行精读时，结合课上所学知识，还算比较流畅地熟悉了代码，在自己进行测试时，也遇到了一些“坑”，其中印象较为深刻的有两个地方：<strong>第一个地方是输入数据没有进行归一化处理，导致在第一次向前传播后经过S函数变化，数值均接近S函数的最大值1；第二个地方是输出的数据和Y矩阵的关系，在我再次理解bp神经网络原理时，了解到每个输出的值域[0,1]表示输出为该值得概率，理解之后问题更改Y矩阵格式问题便解决了。</strong></p>
<p>在这一过程中，也深刻了解了该算法的经典和不足之处，在进行训练数据验证时，发现准确率并不如人意，根据核心算法分析原因，可能是因为输入数据维度不足，输入数据和输出数据的比例不够大，因此不容易区分，因此考虑可以对此方案进行改进：增加球员年龄，身体数据和场上更多详细数据进行输入，还可以寻找球员历年的薪水（因为每年薪水受市场影响，需进行归一化）和数据以获取更多输入。但是由于球员的往年薪水数据并不容易获取，因此这是我下一步需要进行的改进。</p>
<p>同时在这次大作业的完成之中，我发现我所进行的工作量主要在于读懂算法，想出合理的应用环境，获取可用数据上；我的工作量与算法核心的数学内容基本无关，因此这是我未来需要进步的地方，需要不断强化数学基础，能够完成在读懂代码后根据实际项目进行算法改进的工作。</p>
<p>最后，我要感谢老师的在课上细心的讲解，深入到算法的每个细节，让我能对人工神经网络有了清晰地认识！</p>

    </div>

    
    
    
      
  <div class="popular-posts-header">相关文章</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2019\06\01\基于KNN算法的NBA球员数据分析\" rel="bookmark">基于KNN算法的NBA球员数据分析</a></div>
    </li>
  </ul>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Zlatanlong
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://lclong.top/2019/07/01/%E5%9F%BA%E4%BA%8EBP%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E7%9A%84NBA%E7%90%83%E5%91%98%E8%96%AA%E8%B5%84%E8%AF%84%E4%BC%B0/" title="基于BP神经网络的NBA球员薪资评估">https://lclong.top/2019/07/01/基于BP神经网络的NBA球员薪资评估/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/Python/" rel="tag"><i class="fa fa-tag"></i> Python</a>
              <a href="/tags/BP/" rel="tag"><i class="fa fa-tag"></i> BP</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2019/06/01/%E5%9F%BA%E4%BA%8EKNN%E7%AE%97%E6%B3%95%E7%9A%84NBA%E7%90%83%E5%91%98%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/" rel="prev" title="基于KNN算法的NBA球员数据分析">
      <i class="fa fa-chevron-left"></i> 基于KNN算法的NBA球员数据分析
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/02/08/208share/" rel="next" title="2月8日与18级同学分享直播">
      2月8日与18级同学分享直播 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  
  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#一、研究意义"><span class="nav-number">1.</span> <span class="nav-text">一、研究意义</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、数据描述"><span class="nav-number">2.</span> <span class="nav-text">二、数据描述</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#预处理："><span class="nav-number">2.1.</span> <span class="nav-text">预处理：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#归一化："><span class="nav-number">2.2.</span> <span class="nav-text">归一化：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#处理Y矩阵："><span class="nav-number">2.3.</span> <span class="nav-text">处理Y矩阵：</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#三、模型描述"><span class="nav-number">3.</span> <span class="nav-text">三、模型描述</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#典型的神经元模型："><span class="nav-number">3.1.</span> <span class="nav-text">典型的神经元模型：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#神经网络结构（单一输出）："><span class="nav-number">3.2.</span> <span class="nav-text">神经网络结构（单一输出）：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#BP神经网络基本原理："><span class="nav-number">3.3.</span> <span class="nav-text">BP神经网络基本原理：</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#四、算法实现"><span class="nav-number">4.</span> <span class="nav-text">四、算法实现:</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#五、运行结果及意义说明"><span class="nav-number">5.</span> <span class="nav-text">五、运行结果及意义说明:</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#六、总结"><span class="nav-number">6.</span> <span class="nav-text">六、总结</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Zlatanlong"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Zlatanlong</p>
  <div class="site-description" itemprop="description">生活就像巧克力🍫</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">31</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3psYXRhbmxvbmc=" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zlatanlong"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOmxvbmctdHhnY0Bmb3htYWlsLmNvbQ==" title="E-Mail → mailto:long-txgc@foxmail.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      关注列表
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9sZWZsYWNvbi5naXRodWIuaW8v" title="https:&#x2F;&#x2F;leflacon.github.io&#x2F;">leflacon</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9ib2Jib3NzLmdpdGh1Yi5pby8=" title="https:&#x2F;&#x2F;bobboss.github.io&#x2F;">BobBoss</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cDovL29wdGltaXN0aWNhdC54eXovdXNlcj91c2VySWQ9bHpkY2w=" title="http:&#x2F;&#x2F;optimisticat.xyz&#x2F;user?userId&#x3D;lzdcl">lzdcl</span>
        </li>
    </ul>
  </div>

      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 2018 – 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Zlatanlong</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">166k</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> 强力驱动 v4.2.1
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> v7.7.1
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-nest@latest/canvas-nest-nomobile.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'H5inyassVpcpItLTuMJH9aBg-gzGzoHsz',
      appKey     : 'mBzB6QB3deD6zw8YEIKVQdzz',
      placeholder: "快来说两句吧。。。",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
